#!/bin/sh
#
# Launch Station, data sink and data source with associated parameters.
#
# Parameter:	1 - interface (z.B. eth0,...)
#		2 - data sink port
#		3 - data source port
#		4 - team
#		5 - station
#		6 - desired run time
#		
# (by H. Schulz 2011)
#

printUsage() {
	echo  "Usage: $0 <interface> <data sink port> <data source port> <team> <station> <run-time> <multicastAddr> <multicastPort> <syncMode |0 = normal | 1= sync>"
}

# Parameter (..., die auch für Ihre Lösung interessant sein können.)
IfaceName=$1
DataSinkPort=$2
DataSourcePort=$3
Team=$4
Station=$5
Runtime=$6
MCastAddress=$7
ReceivePort=$8
Mode=$9

# Multicast
#MCastAddress=225.10.1.2
#ReceivePort=15016

if [ $# -gt 8 ] ; then
	if [ "$1" = "--help" ] ; then
		printUsage
	else
		# launch data sink
		java datasink.DataSink $DataSinkPort "$Team-$Station" &
		DataSinkPID=$!

		# launch data source
		java datasource/DataSource $DataSourcePort "$Team-$Station" 100 &
		DataSourcePID=$!

		# launch transceiver
		java station.Station $IfaceName $DataSourcePort $DataSinkPort $MCastAddress $ReceivePort $Mode &
		StationPID=$!

		sleep $Runtime

		#stop data sink and data source
		echo "Purging procs..."
		kill -9 $DataSinkPID
		kill -9 $DataSourcePID
		kill -9 $StationPID
		echo "Done."

		exit $?
	fi
else
	printUsage
	exit 1
fi
